<template>
	<scroll-view class="scrollView" scroll-x :scroll-left="currleft" @scroll="scroll">
		<view class="scrollContain" :style="{justifyContent: tabs.length<=5?'space-between':''}">
			<view class="tabItem"  :class="currentIndex==index?'active':''" v-for="(item , index) in tabs" :style="{borderColor: currentIndex!==index?'': border ,color: currentIndex==index&&acctiveText?border:'#606266'}"
			 :key="index" @click="itemClick(item, index)">
				{{isCate?item.catName:item}}
			</view>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				currentIndex: 0,
				scroolleft: 0,
				currleft: 0
			};
		},
		props: {
			isCate:false,
			tabs: Array,//标签数组
			border: String,//选中是下边框颜色
			acctive: {//选中下标
				type: Number,
				default: 0
			},
			acctiveText: {//选中是文本是否一起变色
				type: Boolean,
				default: false
			}
		},
		created(){
			this.currentIndex=this.acctive
		},
		methods: {
			scroll(e) {
				this.scroolleft = e.detail.scrollLeft
			},
			backleft() {
				this.currleft = this.scroolleft
				this.currentIndex = 0
				this.$nextTick(function() {
					this.currleft = 0
				})
			},
			itemClick(item, index) {
				this.currentIndex = index
				this.$emit('tabClick', {
					item,
					index
				})
			}
		},
		
	}
</script>

<style lang="scss">
	.scrollView {
		background-color: #fff;
		&::-webkit-scrollbar {
			display: none;
			width: 0 !important;
			height: 0 !important;
			-webkit-appearance: none;
			background: transparent;
		}

		.scrollContain {
			@extend %flexVcenter;
			background-color: #fff;

			.tabItem {
				min-width:150upx;
				text-align: center;
				height: 5vh;
				line-height: 5vh;
				font-size: $uni-font-size-base;

			}

			.active {
				border-bottom-style: solid;
				border-bottom-width: 2px;
			}

		}
	}
</style>
